using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.Library.DataStructure;
using Entity;

namespace AutoGear.BLL
{
    public class Inquires
    {
        #region Inquires Private Fields

        int _inquiryId;
        string _name = string.Empty;
        string _organization = string.Empty;
        string _telephone = string.Empty;
        string _emailAddress = string.Empty;
        string _website = string.Empty;
        string _subject = string.Empty;
        string _inquires = string.Empty;
        DateTime _createDate;
        bool _isContacted;

        #endregion

        #region Inquires Constractor
        public Inquires() { }

        public Inquires
        (
            int inquiryId,
            string name,
            string organization,
            string telephone,
            string emailAddress,
            string website,
            string subject,
            string inquires,
            DateTime createDate,
            bool isContacted
        )
        {
            this._inquiryId = inquiryId;
            this._name = name;
            this._organization = organization;
            this._telephone = telephone;
            this._emailAddress = emailAddress;
            this._website = website;
            this._subject = subject;
            this._inquires = inquires;
            this._createDate = createDate;
            this._isContacted = isContacted;
        }

        #endregion

        #region Public Properties


        public int InquiryId
        {
            get { return _inquiryId; }
        }


        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Organization
        {
            get { return _organization; }
            set { _organization = value; }
        }

        public string Telephone
        {
            get { return _telephone; }
            set { _telephone = value; }
        }

        public string EmailAddress
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }

        public string Website
        {
            get { return _website; }
            set { _website = value; }
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        public string Inquiry
        {
            get { return _inquires; }
            set { _inquires = value; }
        }

        public DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }

        public bool IsContacted
        {
            get { return _isContacted; }
            set { _isContacted = value; }
        }



        #endregion

        public void Create()
        {

            try
            {
                this._inquiryId = TblInquires.CreateNewTblInquires(Name, Organization, Telephone, EmailAddress, Website, Subject, Inquiry, CreateDate, IsContacted);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public bool Update()
        {
            try
            {
                TblInquires tblInquires = TblInquires.GetTblInquiresByInquiryId(this._inquiryId);
                tblInquires.Name = this._name;
                tblInquires.Organization = this._organization;
                tblInquires.Telephone = this._telephone;
                tblInquires.EmailAddress = this._emailAddress;
                tblInquires.Website = this._website;
                tblInquires.Subject = this._subject;
                tblInquires.Inquires = this._inquires;
                tblInquires.CreateDate = this._createDate;
                tblInquires.IsContacted = this._isContacted;
                return tblInquires.Save();
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public void Delete()
        {
            throw new Exception("Method not implemented");
        }



        public static Inquires Load(int inquiryId)
        {
            try
            {
                TblInquires tblInquires = TblInquires.GetTblInquiresByInquiryId(inquiryId);
                Inquires inquires = new Inquires(tblInquires.InquiryId, tblInquires.Name, tblInquires.Organization, tblInquires.Telephone, tblInquires.EmailAddress, tblInquires.Website, tblInquires.Subject, tblInquires.Inquires, tblInquires.CreateDate, tblInquires.IsContacted);
                return inquires;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public static ReadWriteCustomCollection<Inquires> GetBackendInquiresList(string orderBy, int startIndex, int pageSize)
        {
            return LoadFromCustomCollection(TblInquires.GetAllTblInquiresPaged(orderBy, startIndex, pageSize));
        }

        public static int GetBackendInquiresListCount()
        {
            return TblInquires.GetAllTblInquiresPagedCount("", 0, 0);

        }

        private static ReadWriteCustomCollection<Inquires> LoadFromCustomCollection(ECommerce.DAL.CustomCollection<TblInquires> tblInquires)
        {
            ReadWriteCustomCollection<Inquires> result = new ReadWriteCustomCollection<Inquires>();
            for (int i = 0; i < tblInquires.Count; i++)
            {
                TblInquires tmpTblInquires = tblInquires[i];
                result.Add(new Inquires(tmpTblInquires.InquiryId, tmpTblInquires.Name, tmpTblInquires.Organization, tmpTblInquires.Telephone, tmpTblInquires.EmailAddress, tmpTblInquires.Website, tmpTblInquires.Subject, tmpTblInquires.Inquires, tmpTblInquires.CreateDate, tmpTblInquires.IsContacted));
            }
            return result;
        }


    }
}
